#pragma once

#include "resource.h"
#include "ThreadSchedule.h"
#include "ViewTaskList.h"

// CFormTask form view

class CFormTask : public CFormView
{
	DECLARE_DYNCREATE(CFormTask)

protected:
	CFormTask();           // protected constructor used by dynamic creation
	virtual ~CFormTask();

public:
	enum { IDD = IDD_FORM };
#ifdef _DEBUG
	virtual void AssertValid() const;
#ifndef _WIN32_WCE
	virtual void Dump(CDumpContext& dc) const;
#endif
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

	DECLARE_MESSAGE_MAP()

public:
	virtual void	OnInitialUpdate();
	afx_msg void	OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
	afx_msg HBRUSH	OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
	afx_msg void	OnUpdateFileOpen(CCmdUI *pCmdUI);
	afx_msg void	OnFileOpen();

	afx_msg void	OnBnClickedBtnBrowse();
	afx_msg void	OnBnClickedStart();	
	afx_msg void	OnBnClickedRadioShutdown();
	afx_msg void	OnBnClickedRadioClose();
	afx_msg void	OnBnClickedRadioActionnone();

	afx_msg LRESULT OnTaskSetParamFinished(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnTaskExecState(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnScheduleFinished (WPARAM wParam, LPARAM lParam);

public:
	void			Init(CViewTaskList* pView,Tasks* pts) {  m_pViewTaskList = pView; m_pViewTaskList->SetTasks(pts);};	
	void			WaitScheduleThreadEnd() { 
		if (m_hThread) {
				::PostThreadMessage(m_dwThreadID, WM_QUIT,0,0);	// if m_dwThreadID valid then we archived out goal, otherwise, nothing bad.
				::WaitForSingleObject(m_hThread, INFINITE);
			}
		};
	CThreadSchedule*		GetThread() const { return m_pThread; }
	CString					GetSvr() const { return m_sSvr; }
	CString					GetUsr() const { return m_sUsr; }

protected:
	CThreadSchedule*		m_pThread;		// schedule thread.
	DWORD					m_dwThreadID;	// stores schedule thread id
	HANDLE					m_hThread;		// schedule thread handle, used to wait for it to end first.
	CString					m_sUsr;
	CString					m_sPwd;
	CString					m_sSvr;
	CString					m_sTaskFileName;	
	CViewTaskList*			m_pViewTaskList;

public:
	afx_msg void OnEnChangeSvr2();
	UINT m_uElapseTask;
	UINT m_uElapseFailedTask;
	afx_msg void OnEnKillfocusElapsetask();
	afx_msg void OnEnKillfocusElapsefailed();
	// Enter in [ms] the gap between two HTTP request.
	UINT m_BrowserTick;
	afx_msg void OnEnKillfocusBrowsertick();
	BOOL m_bNeedLogOut;
	afx_msg void OnBnClickedLogout();
};


